﻿package com.firewolf.spring.transaction.byxml;

public class BookShopService {

	private IBookShopDao bookDao = null;
	
	public void setBookDao(IBookShopDao bookDao) {
		this.bookDao = bookDao;
	}
	
	/**
	 * 买书服务,需要保证在用户的余额不足时，不再买书，不要扣除书的余库
	 * 即：保证下面的方法是事物的
	 */
	public void buyBook(String bookId,String userName){
		int price = bookDao.findBookPriceById(bookId);
		bookDao.updateBookStock(bookId);
		bookDao.updateUserAccount(userName, price);
	}
}
